package org.example.struct.array;

import com.alibaba.fastjson.JSON;

/**
 * @author liyishan
 * @date 2023/8/1 10:39
 * @apiNote
 */

public class Test00283MoveZeroes {
    public static void main(String[] args) {
        int[] a = new int[]{0, 0, 1, -1,1};
        test(a);
        System.out.println("  array:" + JSON.toJSON(a));
    }


    public static void test(int[] nums) {
        int slow = 0;
        int fast = 0;
        while(fast < nums.length){
            if(nums[fast] != 0){
                swap(nums,slow,fast);
                slow++;
            }
            fast ++;
        }
    }

    public static void swap(int[] nums,int left ,int right){
        int temp = nums[left];
        nums[left] = nums[right];
        nums[right] = temp;
    }
}
